/**
 * 时间转时间戳
 * @param {*} strtime 
 * @param {*} accuracy 
 * @returns 
 */
const dmTimeToTimestamp = (strtime, accuracy = '') => {
  let date = new Date(strtime);
  let time = date.getTime();
  if (accuracy == '') {
    return time;
  } else {
    return Math.ceil(time / 1000);
  }
}

/**
 * 时间戳转时间
 * @param {*} timestamp 
 * @returns 
 */
const dmTimestampToTime = (timestamp) => {
  if ((timestamp + '').length < 13) {
    timestamp = timestamp * Math.pow(10, 13 - (timestamp + '').length)
  }
  let date = new Date(timestamp);
  let Y = date.getFullYear() + '-';
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  let D = date.getDate() + ' ';
  let h = date.getHours() + ':';
  let m = date.getMinutes() + ':';
  let s = date.getSeconds();
  return (Y + M + D + h + m + s);
}

export {
  dmTimeToTimestamp,
  dmTimestampToTime
}